import { reqCategoryList, reqBannerList,reqFloorList } from "@/api"

// home模块的小仓库
const state = {
    categoryList:[], // 三级联动的数据
    bannerList:[], // 轮播图的数据
    floorList:[],  // 楼层的数据
}
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },

    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }
}
const actions = {
    // 通过API里面的接口函数调用，向服务器发请求，获取服务器的数据 
    async categoryList({commit}){
        let result = await reqCategoryList()
        if(result.code == 200){
            // console.log(result);
            commit("CATEGORYLIST",result.data)
        }
        
    },

    // 获取首页轮播图的数据
    async getBannerList({commit}){
        let result = await reqBannerList()
        // console.log(r esult);
        if(result.code == 200){
            commit("GETBANNERLIST",result.data)
        }
    },

    // 获取首页floor图的数据
    async getFloorList({commit}){
        let result = await reqFloorList()
        // console.log(result);
        if(result.code == 200){
            commit("GETFLOORLIST",result.data)
        }      
    },
    
}
const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}